package com.app.sgd.util;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Util {
	private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd/MM/yyyy");

	public static String getDateAsStr(Date date) {
		if (date == null)
			return "";
		else
			return DATE_FORMAT.format(date);
	}
	
	public static String getStrAsDate(String date) {
		if (date == null || date.length()==0)
			return "";
		else
			return date.substring(6,8)+"/"+date.substring(4,6)+"/"+date.substring(0,4);
	}
	
	public static Date getDate(String date) {
		try{
		if (date == null || date.length()==0)
			return null;
		else
			return DATE_FORMAT.parse(date);
		}catch(Exception e){
			return null;
		}
	}
	
	public static String getDateAsYYYYMMDD(String date) {
		if (date == null || date.length()==0)
			return "";
		else
			return date.substring(6,10)+date.substring(3,5)+date.substring(0,2);
	}
}
